package cn.cvs.service;

import cn.cvs.common.SendEMailException;
import cn.cvs.mapper.SysUserMapper;
import cn.cvs.pojo.SysUser;

import java.util.List;

public class SysUserServiceImpl implements SysUserService {
    private SysUserMapper sysUserMapper;

    /**c
     * 获取用户列表
     * @param sysUser
     * @return
     */
    @Override
    public List<SysUser> getList(SysUser sysUser) {
        return sysUserMapper.selectSysUserList(sysUser);
    }

    @Override
    public boolean add(SysUser sysUser) throws SendEMailException {
        // 模拟在一个事务中两次对数据库的操作，第一次操作完成之后发生异常时，第二次未操作未执行，第一次操作也将回滚。两次操作要么都不成功，要么同时成功
        sysUserMapper.add(sysUser);
        // int num = 5 / 0; // 模拟程序中抛出异常
        /*if (sysUser != null) {
            // 手动抛出异常
            throw new SendEMailException("发送通知邮件异常");
        }*/
        sysUserMapper.add(sysUser);
        return true;
    }
}
